package cn.xopencode.scoreservice.dal.mysql.mapper.demand;


import cn.xopencode.common.framework.vo.SortingField;
import cn.xopencode.mybatis.core.query.QueryWrapperX;
import cn.xopencode.mybatis.core.util.PageUtil;
import cn.xopencode.score.api.rpc.demand.dto.ScoreReqDTO;
import cn.xopencode.score.api.rpc.demand.dto.ScoreRespDTO;
import cn.xopencode.scoreservice.dal.mysql.dataobject.demand.ScoreDO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

@Repository
public interface ScoreMapper extends BaseMapper<ScoreDO> {

    /**
     *
     * @return 所有员工每月总分数情况，并按照日期倒叙展示
     */
    List<ScoreDO> selectAllPage();


    default IPage<ScoreDO> selectDatePage(ScoreReqDTO scoreReqDTO) {
        System.out.println("cccccc");
        return selectPage(PageUtil.build(scoreReqDTO, (Collection<SortingField>) scoreReqDTO.getUpdateTime()),
                new QueryWrapperX<ScoreDO>().eqIfPresent("update_time", scoreReqDTO.getUpdateTime()));
    }
//    @Select("select DATE_FORMAT(modify_date, '%Y-%m'),sum(score)\n" +
//            "        from employee_score\n" +
//            "        GROUP BY DATE_FORMAT(modify_date, '%Y-%m')\n" +
//            "        order by DATE_FORMAT(modify_date, '%Y-%m')")


        // DTO --->BO  ---> DO
    default ScoreDO selectByEmpId(String empId){
        return selectOne(new QueryWrapperX<ScoreDO>().eqIfPresent("emp_id", empId));
    }

    void updateSuggestScore(@Param("scoreDO")ScoreDO scoreDO);

    void updateActivityScore(@Param("scoreDO")ScoreDO scoreDO);

    void updateAccidentScore(@Param("scoreDO")ScoreDO scoreDO);

    void clearAccidentScore(@Param("empId")String empId);
}
